<!DOCTYPE html>
<?php session_start(); ?>
<html>
    <head>
        <!--<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">-->
        <meta charset="utf-8"/>
        <link href="index.css" type="text/css" rel="stylesheet" media="screen" />
        <link href="css/index.css" type="text/css" rel="stylesheet" media="screen" />
        <title>MyNote</title>
        <script src="js/validator.js" type="text/javascript" ></script>
				<script type="text/javascript">
					function checkSearch()
					{
						var bookname = document.getElementsByName('consult-book-name');
						if (validator.notEmpty.check(bookname[0].value))
						{
							if (validator.noSpecialSymbols.check(bookname[0].value))
							{
								return true;
							}
							else
							{
								alert(validator.noSpecialSymbols.message);
								return false;
							}
						}
						else
						{
							alert(validator.notEmpty.message);
							return false;
						}
					}
						
				</script>
    </head>
        <body>
            <div class="topbar">
                <div class="loginfo">
                    <ul>
                        <li>
                            <?php
                            if(!isset($_SESSION["session_username"]))
                                {
                                ?>
							
                                <form action="login.php" method="post" onsubmit="return checkAuth()">
								用户名<input type = "text" name="username"/>
								密码<input type = "password" name="password" /> 
                                <input type="submit" value="登陆" />
                            </form>
                            <input type="button" value="注册" onclick="window.location.href = 'RegisterSite.php'"></input>
                            
                            <?php
                            }
                            else
                            {
                                $name = $_SESSION["session_username"];
							?>
								<?=$name?>
								
								<?php
									if(isset($_SESSION["session_admin"]) && $_SESSION["session_admin"] == true)
									{
								?>
									<input type="button" value="用户管理" onclick="window.location.href ='UserControl.php'"/>
								<?php
									}
                                ?>
                                
                                <input type="button" value="注销" onclick="window.location.href ='Logout.php'"/>
                            <?php
                            }
                            ?>
                        </li>
                    </ul>
                </div>
                <div class="globalitems">
                    <ul>
                        <li>
							<a href="index.php">首页</a>
                        </li>
                        <li>
                            <a href="SearchBook.php?allbook=true">书库</a>
                        </li>
                        <li>
                            <a href="showGroup.php">我的群组</a>
                        </li>
                        <li>
							<a href="index.php">随便看看</a>
                        </li>    
                    </ul>
                </div>
            </div>

            <div class="seachbook">
                <div class="consult">
                    <form method="get" action="SearchBook.php" onsubmit="return checkSearch()">
                        <fieldset>
                            <input maxlength="60" size="40" type ="text" name="consult-book-name" value="" id="queryinput"/>
                            <input type="submit" value="查找图书" id="query">
                        </fieldset>
                    </form>

                          <input type="button" value="添加图书" id="addcomments" onclick="window.location.href = 'AddBook.php'">

                </div>
            </div>
            
		<div id="freebook">
			<div class="sub_title">
				重点推荐
			</div>
        	<?php
        		include_once 'Book.php';
				$num = 4;
				$list = Book::randomBook($num);
				for($count = 0; $count<count($list);$count++)
				{
					$pic = $list[$count]->getFace();
					$bkname = $list[$count]->getName();
					// $intro = $list[$count]->getIntro();
			?>
			<div class="bookface">
				<a href="ShowBook.php?bookname=<?=$bkname?>"><img class="book" src="<?=$pic?>"></img></a>
			</div>
			<?php
				}
			?>
		</div>
    </body>
</html>
